<!DOCTYPE html>
<html>
<head>
    <title>登录/注册</title>
    #parse("include/head.html")
    <link href="$request.contextPath/res/css/form.min.css" rel="stylesheet">
    <style>
        body {
            background: #f6f6f6;
        }

        .login-hr {
            margin-top: 10px;
            margin-bottom: 20px;
            border-top: 1px solid #eee;
        }

        .input-lg {
            border-top: none !important;
            line-height: 48px;
            height: 48px;
            font-size: 16px;

        }
    </style>
</head>

<body>
<div class="main">
    <div class="col-xs-12" style="padding-top: 3%">
        <form class="form-horizontal clearfix" role="form">
            <div class="form-group" style="margin-bottom:0 !important;">
                <div class="input-group">
                    <input type="text" class="form-control input-lg"  id="username" name="username"
                           placeholder="请输入手机号">
                    <span class="input-group-btn">
                        <button type="button" id="dynamicPwdBtn"
                                style="border-radius: 0;height: 48px;font-size: 14px;font-weight: bold;" class="btn btn-danger">
                            获取动态密码
                        </button>
                    </span>
                </div>
            </div>
            <div class="form-group">
                <input type="text" class="form-control input-lg" name="password" id="password"
                       placeholder="请输入动态密码">
            </div>
            <div class="col-xs-12 container" style="padding-top: 5%">
                <button type="button" id="loginBtn" class="btn btn-danger btn-block text-center"
                        style="width:100%;font-weight: bold;padding: 10px 12px;">确 定
                </button>
            </div>
        </form>
    </div>
    <!--<div class="col-xs-12" style="padding-top: 10%">
        <div class="clearfix">
            <div class="row">
                <div class="col-xs-3">
                    <hr class="login-hr"/>
                </div>
                <div class="col-xs-6 text-center">
                    <span style="color: #666">第三方帐号登录</span>
                </div>
                <div class="col-xs-3">
                    <hr class="login-hr"/>
                </div>
            </div>
            <div class="row">
                <div class="col-xs-4 col-xs-offset-3">
                    <img src="$request.contextPath/res/images/shared_qq.png" style="width: 40px">
                </div>
                <div class="col-xs-5">
                    <img id="wechatLoginBtn" src="$request.contextPath/res/images/shared_wx.png" style="width: 40px">
                </div>
            </div>

        </div>
    </div>-->

</div>
#parse("include/libs.html")


<script type="text/javascript">
    $(function () {
        $('#loginBtn').click(function () {
            if ($('#username').val() == '') {
                swal({
                    text: "请输入手机号，获取动态密码",
                    timer: 3000,
                    showButtonContainer: false
                });
                return;
            }
            if ($('#password').val() == '') {
                swal({
                    text: "请输入密码",
                    timer: 2000,
                    showButtonContainer: false
                });
                return;
            }

            $.ajax({
                type: "POST",
                url: 'user/login',
                data: {username: $('#username').val() , password: $('#password').val()},
                success: function (data) {
                    $("#loginBtn").prop('disabled', false);
                    if (data) {
                        swal({
                            text: "登录成功111",
                            timer: 3000,
                            showButtonContainer: false,
                            type:'success'
                        });
                        document.location.href = document.referrer;
                    } else {
                        swal({
                            text: "系统繁忙，请稍候重试!",
                            timer: 3000,
                            showButtonContainer: false,
                            type:'error'
                        });
                    }
                },
                error: function () {
                    $("#loginBtn").prop('disabled', false);
                    swal({
                        text: "系统繁忙，请稍候重试!",
                        timer: 3000,
                        showButtonContainer: false,
                        type:'error'
                    });
                },
                dataType: 'JSON'
            });

        });

        $('#wechatLoginBtn').click(function(){
            swal({
                text: "正在跳转到微信...",
                timer: 3000,
                showButtonContainer: false
            });
            document.location.href = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx7c285115781a7c91&redirect_uri='+encodeURIComponent('http://i.faaay.com/mobile/user/wechat')+'&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect';
        });


        $('#dynamicPwdBtn').click(function () {
            if ($('#username').val() == '') {
                swal({
                    text: "请输入手机号，获取动态密码",
                    timer: 3000,
                    showButtonContainer: false
                });
            }
            $.ajax({
                type: "GET",
                url: 'user/dynamicPwd',
                data: {username: $('#username').val()},
                success: function (data) {
                    $("#dynamicPwdBtn").prop('disabled', false);
                    if (data) {
                        swal({
                            text: "获取成功，请注意查收短信！",
                            timer: 3000,
                            showButtonContainer: false,
                            type:'success'
                        });

                    } else {
                        swal({
                            text: "系统繁忙，请稍候重试!",
                            timer: 3000,
                            showButtonContainer: false,
                            type:'error'
                        });
                    }
                },
                error: function () {
                    $("#dynamicPwdBtn").prop('disabled', false);
                    swal({
                        text: "系统繁忙，请稍候重试!",
                        timer: 3000,
                        showButtonContainer: false,
                        type:'error'
                    });
                },
                dataType: 'JSON'
            });
        });
    });
</script>
</body>
</html>